unit LibImportUnit;

interface

uses
  Windows;

const
  TcpFileServerLib = 'TcpFileServerLib.dll';
  CollectionLib = 'Collection.dll';
//  EncryptLib = 'Encrypt.dll';
  UtilLib = 'Util.dll';

var
  TcpFileServerHandle,
  CollectionHandle,
  UtilHandle: THandle;
  LibLoaded: Boolean;

  StartTcpFileServer: function(APort: Integer): Integer; stdcall;
  StopTcpFileServer: function(AHandle: Integer): Integer; stdcall;
  CheckRegisterInfo: function(): Boolean; stdcall;
  GetTcpFileServerClientCount: function(AHandle: Integer): Integer; stdcall;

  //Collection
  CollectionServerStart: function: Integer; stdcall;
  CollectionServerStop: function: Integer; stdcall;
  
implementation

function LoadLibs: Boolean;
begin
  Result := False;

//  TcpFileServerHandle := LoadLibrary( TcpFileServerLib );
//  if TcpFileServerHandle = 0 then
//    Exit;
//
//  @StartTcpFileServer := GetProcAddress(TcpFileServerHandle, 'StartTcpFileServer');
//  @StopTcpFileServer := GetProcAddress(TcpFileServerHandle, 'StopTcpFileServer');
//  @GetTcpFileServerClientCount := GetProcAddress(TcpFileServerHandle, 'GetTcpFileServerClientCount');
//  if (@StartTcpFileServer = nil) or (@StopTcpFileServer = nil) then
//    Exit;

//  UtilHandle := LoadLibrary( UtilLib );
//  if UtilHandle = 0 then
//    Exit;                    
//
//  @CheckRegisterInfo := GetProcAddress(UtilHandle, 'CheckRegisterInfo');
//  if @CheckRegisterInfo = nil then
//    Exit;

  CollectionHandle := LoadLibrary( CollectionLib );
  if CollectionHandle = 0 then
    Exit;

  @CollectionServerStart := GetProcAddress(CollectionHandle, 'CollectionServerStart');
  @CollectionServerStop := GetProcAddress(CollectionHandle, 'CollectionServerStop');

  Result := True;
end;


function FreeLibs: Boolean;
begin
  Result := False;

//  if TcpFileServerHandle = 0 then
//    Exit;
//
//  FreeLibrary( TcpFileServerHandle );

//  if UtilHandle = 0 then
//    Exit;

//  FreeLibrary( UtilHandle );

  if CollectionHandle = 0 then
    Exit;

  FreeLibrary( CollectionHandle );
end;

initialization
  LibLoaded := LoadLibs;

finalization
  if LibLoaded then
    FreeLibs;

end.
